<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <link rel="stylesheet" href="../res/css/weui.css" />
    <link rel="stylesheet" href="../res/css/weuix.css" />
	<link rel="stylesheet" href="../res/css/common.css" />
    <!-- <link rel="stylesheet" href="../res/css/mp_common.css" /> -->
    <!-- <script src="../res/js/rem.js"></script> -->
    <script src="../res/js/zepto.min.js"></script>
    <script src="../res/js/zepto.weui.js"></script>
    <script src="../res/js/common.js?v=1"></script>
    <script src="../res/js/template-web.js"></script>
    <script>
        var strOrgId,strOpenId,strUserId;
        $(function () {
			template.defaults.imports.isHis = isHis

			strOrgId =getQst("orgid");
			strOpenId = getQst("openid");
			strUserId = getUserId();
			var paramJson = {
				"current": 1,			//当前页,示例值(1)
				"endTime": "",			//结束时间
				"readState": "",		//患者查看诊断的状态0未读，1已读,空则全部
				"size": 100,			//每页大小,示例值(10)
				"startTime": "",		//开始时间
				"userId":strUserId,
				isOverdue: 1
			}
			newAjaxPost("/h5/patientPrescription/getPatientPrescriptionList", paramJson, doLoginOk);
			function doLoginOk(rstData){
				if (rstData.code == "1" && rstData.data.list.length > 0) {
					//生成html片段
					// console.log(rstData.data);
					var html = template("recipeList",rstData.data);
					var container = document.getElementById("recipe_list");
					//将html片段渲染到界面中
					container.innerHTML = html;
				}else{
					//生成html片段
					var html = template("noData",rstData);
					var container = document.getElementById("recipe_list");
					//将html片段渲染到界面中
					container.innerHTML = html;
				}
			}
			//返回上页
			$('#btnBack').on("click", function () {
				// history.go(-1);
				// goPage("inquiry_doctor_index.htm");
				goPage("inquiry_user_personal.htm?orgid=" + strOrgId + "&openid=" + strOpenId);
			});

			$(".tab-item").on('click', function (e) {
				console.log($(this).attr('data-index'));
				$(this).addClass('active').siblings().removeClass('active')
				const params = {
					"current": 1,
					"size": 100,
					"userId":strUserId,
					isOverdue: $(this).attr('data-index')
				}
				setTimeout(() => {
					newAjaxPost("/h5/patientPrescription/getPatientPrescriptionList", params, doLoginOk);
				}, 0);

			})
		})
		function goToDetail(obj){
			let {prescriptionNo, id, paymentMethod, storeId, inquiryType, payWay} = obj
			var order_id = prescriptionNo
			// id
			var payment_method = paymentMethod
			var inside = !storeId
			var type = inquiryType
			// payWay
			goPage('./inquiry_go_order.htm?order_id='+order_id+'&id='+id+'&paymentMethod='+payment_method+'&inside='+ inside +'&type='+type+'&payWay='+payWay);
		}
		function goToStop(state){
			if(state==2){
				msgInfo('药师审核不通过')
			}else{
				msgInfo('医生正在审核中，请稍后再查看')
			}
		}
		function goToOrder(obj){
			let {prescriptionNo, id, paymentMethod, storeId, inquiryType, payWay} = obj
			var order_id = prescriptionNo
			var payment_method = paymentMethod
			var inside = !storeId
			var type = inquiryType

			goPage('user_dtl1.htm?prescription_id=' + order_id + '&user_id=' + getUserId() + '&id=' + id + '&inside=' + inside)
		}
    </script>
</head>
<style>
	.fixed-top{
		border-bottom:1px solid #e8e8e8;
		position: sticky;
		position: -webkit-sticky;
		left:0;
		top:0;
		right:0;
		z-index: 99;
		background:#F6F6F9;
	}
	.weui-navbar{
		background-color: #ffffff;
	}
	.prescriptionlist{
	    overflow: hidden;
	    position: relative;
	    padding: 12px;
		background: #ffffff;
		margin: 15px;
	    border-radius: 10px;
	    padding-bottom: 8px;
	}
	.prescriptionlist_image{
	    width: 56px;
	    height: 56px;
	    border-radius: 50%;
	    overflow: hidden;
	    float: left;
	}
	.prescriptionlist_name{
	    font-size: 15px;
	    float: left;
	    width: 77%;
	    height: 56px;
	    line-height: 28px;
	    margin-left: 10px;
	}
	.nickname{
	    background-color: #ECF6FF;
	    color: #1189FF;
	    width:61px;
	    height:19px;
	    border-radius:5px;
	    font-size: 12px;
	    padding: 2px 8px;
	    margin-left: 10px;
	}
	.lrsj{
		width: 270px;
	    float: left;
	    font-size: 13px;
	    color: #353535;
	}
	.prescriptionlist_type,.prescriptionlist_id{
	   font-size: 14px;
	   color: #353535;
	   margin: 2px 0;
	   padding: 5px 0;
	}
	.prescriptionlist .prescriptionlist_type:nth-child(6){
	    /* border-bottom: 1px solid #f8f7f7; */
		padding-bottom: 0;
	    padding-top: 0px;
	}
	.prescriptionlist .prescriptionlist_type:nth-child(5){
	    padding-top: 0px;
	}
	.button{
	    width: 30%;
	    border-radius: 10px;
	    background: #1189FF;
	    font-size: 13px;
	    line-height: 29px;
	    height: 32px;
	    margin-top: 5px;
	    display: inline-block;
		float: right;
		border: 0;
		color: white;
	}
	.icon{
		 margin: 0;
		 font-size: 16px;
	}
	/* #recipe_list{
		margin-top: 55px;
	} */

	/* 右上小标签 */
	.has-tag::after{
		display: block;
		position: absolute;
		padding: 0px 7px;
		right: 5px;
		top: 5px;
		font-size: 12px;
		color: #1189FF;
		border: 1px solid #1189FF;
		border-radius: 5px;
	}

	.is-medical-insurance::after{
		content: "医保";
	}

	.inside-hospital::after{
		content: "院内";
	}

	.offline-query::after{
		content: "自主开方";
	}
	
	.button.under-review{
		background-color: #f9a821;
	}
	.click-mask{
		position: absolute;
		top: 0;
		bottom: 0;
		left: 0;
		right: 0;
		/* background-color: #5552; */
	}
	.recipe-tab{
		background-color: #fff;
		display: flex;
	}
	.tab-item, .tab-item-unclick{
		flex: 1;
		text-align: center;
		line-height: 40px;
		position: relative;
	}
	.tab-item-unclick{
		font-weight: bold;
	}
	.tab-item.active{
		color: #1189FF;
		font-weight: bold;
	}
	.tab-item.active::after{
		content: '';
		position: absolute;
		bottom: 0;
		left: 0;
		right: 0;
		height: 2px;
		background-color: #f9a821;
	}
	.filter-icon{
		width: 16px;
		height: 16px;
		vertical-align: middle;
	}
	.z-top{
		position: relative;
		z-index: 19;
	}
</style>
<body style="width:100%; height:unset; min-height: 100%;">
	<div class="fixed-top">
		<div class="weui-header weui-btn_primary"> 
			<div class="weui-header-left"><a id="btnBack" class="icon icon-109"></a></div>
			<div class="weui-header-title">我的处方</div>
			<div class="weui-header-right"></div>
		</div>

		<div class="recipe-tab">
			<div class="tab-item" data-index="0">全部</div>
			<div class="tab-item active" data-index="1">未过期</div>
			<div class="tab-item" data-index="2">已过期</div>
			<div class="tab-item-unclick">
				<img src="../res/images/1.9.1img/sxicon.png" class="filter-icon">
				筛选
			</div>
		</div>
    </div>
    <div id="recipe_list">
    </div>
    <script id="recipeList" type="text/html">
        {{each list value}}
			<!-- 非his系统 自主开方 -->
			{{ if !$imports.isHis && value.inquiryType == '5' }} 
			<!-- <div class="prescriptionlist has-tag offline-query" > -->
			<div class="prescriptionlist" >

			<!-- his系统 医保付费 院内药房 显示医保标签 -->
			{{ else if $imports.isHis && value.paymentMethod == 2 && !value.storeId }} 
			<div class="prescriptionlist has-tag is-medical-insurance" >
				
			<!-- 非his系统 医保付费 显示医保标签 -->
			{{ else if !$imports.isHis && value.paymentMethod == 2 }} 
			<div class="prescriptionlist has-tag is-medical-insurance" >

			<!-- his系统 院内药房 显示院内标签 -->
			{{ else if $imports.isHis && !value.storeId }}
			<div class="prescriptionlist has-tag inside-hospital">

			{{ else }}
			<div class="prescriptionlist" >
			{{ /if }}
				<div class="prescriptionlist_image"><img src="{{value.doctorAvatar}}"></div>
				<div class="prescriptionlist_name">{{value.doctorName}}
					<span class="nickname">主诊医生</span>
					<span class="lrsj">{{value.createTime}}</span>
				</div>
				<div class="clear"></div>
				<div class="prescriptionlist_type">开单科室：{{value.departmentName}}</div>
				<div class="prescriptionlist_type">处方单号：{{value.prescriptionNo}} </div>
				<div class="prescriptionlist_type">参考价格：{{value.prescriptionPrice}}元 </div>

				{{if value.prescriptionAllState == '4' || value.payWay == 'offline'}}
				<!-- <div class="click-mask" onclick="goToDetail(this)" data-orderId="{{value.prescriptionNo}}" data-id="{{value.id}}" data-payM="{{value.paymentMethod}}" data-inside="{{!value.storeId}}" data-type="{{value.inquiryType}}" data-payWay="{{value.payWay}}"></div> -->
				<div class="click-mask" onclick="goToDetail({{value}})"></div>
				<button class="button z-top" onclick="goToOrder({{value}})">购买</button>

				{{else if value.prescriptionAllState == '5'}}
				<div class="click-mask" onclick="goToDetail({{value}})"></div>

				{{else if value.prescriptionState == '3'}}
				<button class="button under-review">审核中</button>
				<div class="click-mask" onclick="goToStop(3)"></div>

				{{else if value.prescriptionState == '2'}}
				<button class="button under-review">审核驳回</button>
				<div class="click-mask" onclick="goToStop(2)"></div>
				
				{{/if}}

			</div>
		{{/each}}
    </script>
	<script id="noData" type="text/html">
		<div class="prescriptionlist" style="text-align: center; padding-bottom: 12px;">
			未找到处方
		</div>
	</script>
</body>
</html>